import json
import os
from pymongo import MongoClient

# json_path1 = 'D:/PycharmProjects/pingan_data/json_data/'
# json_path2 = 'D:/PycharmProjects/xywy_data/json_data/'
# json_path3 = 'D:/PycharmProjects/39html_data/json_data/'
# json_path4 = 'D:/PycharmProjects/39html_data/json_data/second_part/'


json_path1 = 'D:/PycharmProjects/three_source_json_data/39/json_data/'
json_path2 = 'D:/PycharmProjects/three_source_json_data/pingan/json_data/'
json_path3 = 'D:/PycharmProjects/three_source_json_data/xywy/json_data/'

path_list = [json_path1, json_path2, json_path3]

path = 'D:/PycharmProjects/three_source_json_data/z_fusion'

conn = MongoClient("mongodb://xiaotuo:n8nRn78BirC8xnvM@192.168.1.3:31935/pingan")

db = conn.pingan
collection = db['disease']


def insert_db(path):
    for i in range(len(os.listdir(path))):
        print(i)
        filename = os.listdir(path)[i]
        # filename = 'xhdbeb.json'
        try:
            with open(os.path.join(path, filename), mode='r', encoding='utf-8') as f:
                json_data = json.load(f)
        except:
            continue
        collection.insert(json_data)


if __name__ == '__main__':
    directory = os.listdir(path)
    for d in directory:
        full_path = os.path.join(path, d)
        insert_db(full_path)
